package main.test.SparkAPI.Baics.singletonObj
class Person(val name:String, val age:Int)
object Person {
  def apply(p1:Person,p2:Person):Person = {
    val name = s"Son of ${p1.name} and ${p2.name}"
    val age = 0
    new Person(name, age)

  }
  def apply(name:String):Person = new Person(name, 0)
  def apply(age:Int):Person = new Person("Mr Unkown",age)

  /**
   * Once you have defined an apply method, you can use it the same way as any other
   * static method implemented in the companion object.You can declare
   * multiple aplly functions in the companion object, as long
   * as their signature is uniquely idenfifiable by
   * the compiler. Consider the following snippet of code.
   * {{{
   *   object Person {
   *    def apply(name:String):Person = new Person(name, 0)
   *    def apply(age:Int):Person = new Person("Mr Unkown",age)
   *   }
   * }}}
   */

  /**
   * The two apply methods have the same name and return type.
   * but they take different parameters:the first takes a string
   * while the second an integer. The  two implementations can
   * coexist because the comp8iler can select one or the other by looking at the types
   * of their parameters.You can refer to the concept of having multiple functions
   * with the same name but different parameters with the term function overloading.
   * Developers ofter use the apply function to create class instances. The
   * compiler offers you some syntactic sugar so that you
   * can omit the function name apply.When passing a paramter ot an object,
   * it looks for an apply method defined in that object with parameters that match
   * the ones you have given. Consider the following snippet fo code;
   * the two expressions Person.apply(tom,alice) and Person(tom,alice) are
   * equivalent:
   *
   * {{{
   *   val tom = new Person("Tom", 24)
   *   val alice = new Person("Alice", 23)
   *   Person.apply(tom, alice)
   *   Person(tom,alice)
   * }}}
   *
   */

}
